//
//  DownTableViewCell.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/24.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "DownTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "User.h"
#import "TypeFour.h"

@interface DownTableViewCell ()

@property (nonatomic, retain) UIView *superView;

@property (nonatomic, retain) UIImageView *picImage;

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UILabel *timeLabel;

@property (nonatomic, retain) UILabel *dayLabel;

@property (nonatomic, retain) UILabel *personLabel;

@property (nonatomic, retain) UILabel *adressLabel;

@property (nonatomic, retain) UILabel *userLabel;

@property (nonatomic, retain) UIImageView *userimageView;

@end

@implementation DownTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubViews];
        self.contentView.backgroundColor = [UIColor colorWithRed:0.976 green:0.953 blue:0.886 alpha:1.000];
    }
    
    return self;
}

- (void)createSubViews {
    
    self.superView = [[UIView alloc] initWithFrame:CGRectMake(10 * ADAPT_WIDTH, 0, SCREEN_WIDTH - 20 * ADAPT_WIDTH, 200 * ADAPT_HEIGHT)];
    self.superView.layer.cornerRadius = 5;
    self.superView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.superView];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.superView.bounds];
    [imageView setImage:[UIImage imageNamed:@"poi_bg_placeholder"]];
    [self.superView addSubview:imageView];
    
    CGRect frame = self.superView.bounds;
    frame.size.width = frame.size.width * 2 / 5;
    UIImageView *blackImage = [[UIImageView alloc] initWithFrame:frame];
    [blackImage setImage:[UIImage imageNamed:@"trips_cover_mask"]];
    [self.superView addSubview:blackImage];
    
    self.picImage = [[UIImageView alloc] initWithFrame:self.superView.bounds];
    self.picImage.contentMode = UIViewContentModeScaleAspectFill;
    [self.superView addSubview:self.picImage];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, self.superView.frame.size.width - 40, 35)];
    self.titleLabel.font = [UIFont systemFontOfSize:22 weight:1.3];
    self.titleLabel.shadowColor = [UIColor grayColor];
    self.titleLabel.shadowOffset = CGSizeMake(1, 1);
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.titleLabel];
    
    UIImageView *aview = [[UIImageView alloc] initWithFrame:CGRectMake(22, self.titleLabel.frame.size.height + 13, 4, 25)];
    aview.layer.cornerRadius = 2;
    aview.layer.masksToBounds = YES;
    aview.image = [UIImage imageNamed:@"login_btn.png"];
    [self.superView addSubview:aview];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, self.titleLabel.frame.size.height + 10, 80, 15)];
    self.timeLabel.font = [UIFont systemFontOfSize:12 weight:1];
    self.timeLabel.shadowColor = [UIColor grayColor];
    self.timeLabel.shadowOffset = CGSizeMake(1, 1);
    self.timeLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.timeLabel];
    
    self.dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLabel.frame.size.width + 35, self.titleLabel.frame.size.height + 10, 40, 15)];
    self.dayLabel.font = [UIFont systemFontOfSize:12 weight:1];
    self.dayLabel.shadowColor = [UIColor grayColor];
    self.dayLabel.shadowOffset = CGSizeMake(1, 1);
    self.dayLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.dayLabel];
    
    self.personLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.dayLabel.frame.size.width + self.dayLabel.frame.origin.x + 10, self.titleLabel.frame.size.height + 10, 100, 15)];
    self.personLabel.font = [UIFont systemFontOfSize:12 weight:1];
    self.personLabel.shadowColor = [UIColor grayColor];
    self.personLabel.shadowOffset = CGSizeMake(1, 1);
    self.personLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.personLabel];
    
    self.adressLabel = [[UILabel alloc] initWithFrame:CGRectMake(33,self.timeLabel.frame.origin.y + self.timeLabel.frame.size.height, 200, 15)];
    self.adressLabel.font = [UIFont systemFontOfSize:10 weight:0.5];
    self.adressLabel.shadowColor = [UIColor grayColor];
    self.adressLabel.shadowOffset = CGSizeMake(0.5, 0.5);
    self.adressLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.adressLabel];
    
    self.userimageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, self.superView.frame.size.height - 50, 30, 30)];
    self.userimageView.layer.cornerRadius = 15;
    self.userimageView.layer.masksToBounds = YES;
    [self.superView addSubview:self.userimageView];
    
    self.userLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, self.superView.frame.size.height - 50, 150, 30)];
    self.userLabel.font = [UIFont systemFontOfSize:13 weight:0.5];
    self.userLabel.textColor = [UIColor whiteColor];
    [self.superView addSubview:self.userLabel];
    
}

- (void)setTypeFour:(TypeFour *)typeFour {
    
    _typeFour = typeFour;
    [self.picImage sd_setImageWithURL:[NSURL URLWithString:self.typeFour.cover_image]];
    self.titleLabel.text = self.typeFour.name;
    self.timeLabel.text = [NSString stringWithFormat:@"%@.%@.%@", [self.typeFour.first_day substringToIndex:4], [self.typeFour.first_day substringWithRange:NSMakeRange(5, 2)], [self.typeFour.first_day substringFromIndex:8]];
    self.dayLabel.text = [NSString stringWithFormat:@"%@ 天", self.typeFour.day_count];
    self.personLabel.text = [NSString stringWithFormat:@"%@ 浏览", self.typeFour.view_count];
    self.adressLabel.text = self.typeFour.popular_place_str;
    [self.userimageView sd_setImageWithURL:[NSURL URLWithString:self.typeFour.users.avatar_m] placeholderImage:[UIImage imageNamed:@"avatar_placeholder_26"]];
    self.userLabel.text = [NSString stringWithFormat:@"by %@", self.typeFour.users.name];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
